package asteroids.model.expressions;

import exceptions.*;;

/**
 * A subclass of expression (E) that represents the the Add (+) operation
 * 
 * @version 1.0
 * 
 * @author	Thijs Peirelinck & Wouter Parys
 *
 */

public class Add extends Operation {
	
	public Add(E e1, E e2) {
		super(e1, e2);
	}
	
	@Override
	public Double getValue() throws IllegalOperandException {
		if(this.isValidExpression() == false) { throw new IllegalOperandException(); }
		Double left = (Double)getLeftOperand().getValue();
		Double right = (Double)getRightOperand().getValue();
		return (left.doubleValue() + right.doubleValue());

	}
	
	@Override
	public String toString() {
		return getLeftOperand().toString() +  " + " + getRightOperand().toString();
	}
	
	@Override
	public Add createCopy() {
		return new Add(getLeftOperand().createCopy(),getRightOperand().createCopy());
	}
	
}
